package com.spark.common.widget

import com.just.agentweb.AgentWebUtils
import android.widget.FrameLayout
import android.os.Build
import android.app.Activity
import android.content.Context
import android.support.annotation.Nullable
import android.util.AttributeSet
import android.view.View
import com.coolindicator.sdk.CoolIndicator
import com.just.agentweb.BaseIndicatorView


class CoolIndicatorLayout(context: Context, @Nullable attrs: AttributeSet? = null, defStyleAttr: Int = -1) : BaseIndicatorView(context, attrs, defStyleAttr) {
    private var mCoolIndicator: CoolIndicator? = null

    init {
        mCoolIndicator = CoolIndicator.create(context as Activity)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCoolIndicator!!.progressDrawable = context.getResources().getDrawable(com.coolindicator.sdk.R.drawable.default_drawable_indicator, context.getTheme())
        } else {
            mCoolIndicator!!.progressDrawable = context.getResources().getDrawable(com.coolindicator.sdk.R.drawable.default_drawable_indicator)
        }

        this.addView(mCoolIndicator, offerLayoutParams())

    }

    override fun show() {
        this.visibility = View.VISIBLE
        mCoolIndicator!!.start()
    }

    override fun setProgress(newProgress: Int) {}

    override fun hide() {
        mCoolIndicator!!.complete()
    }

    override fun offerLayoutParams(): FrameLayout.LayoutParams {
        return FrameLayout.LayoutParams(-1, AgentWebUtils.dp2px(context, 3f))
    }

    companion object {

        private val TAG = CoolIndicatorLayout::class.java.simpleName
    }
}